<%-- 
    Document   : edit_visit
    Created on : Apr 22, 2014, 4:59:47 AM
    Author     : Mansur
--%>

<%@ include file="/WEB-INF/jsp/include/page_header.jspf" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>.: Ship Visit :.</title>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.10.2.custom.js"></script>
        <script type="text/javascript">
            function autoComplete(){
//                alert('autocomplete');
                var match = ${fn:length(actionBean.listSub)};
//                alert('match ='+match);
                for(var i = 1; i <= match; i++){
//                    alert(i+') '+$('#details_'+i).val());
                    if($('#details_'+i).val() === ''){
                        $('#details_'+i).val("NONE");
//                        alert('alter '+i+') '+$('#details_'+i).val());
                    }
                }
                
                var subMatch = ${fn:length(actionBean.listSubExtend)};
//                alert('submatch ='+subMatch);
                for(var i = 1; i <= subMatch; i++){
//                    alert(i+') '+$('#sdetails_'+i).val());
                    if($('#sdetails_'+i).val() === ''){
                        $('#sdetails_'+i).val("NONE");
//                        alert('alter '+i+') '+$('#sdetails_'+i).val());
                    }
                }
            }
            
            function reSubmit(idVisit,flag,stage){
                var frm = document.forms.formList;
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?viewEditForm&flagEdit='+flag+'&stage='+stage+'&idVisit='+idVisit;
                frm.action = url;
                frm.submit();
            }
            
            function updateDetails(id,detail,flag,type,loc){
                if(type === 'S'){
                    detail = detail.toUpperCase();
                }
                
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?updateAction&idcrew=' + id + '&detail=' + detail + '&flag=' +flag;
                $.get(url,
                        function(data) {
                            if(flag === 's')
                                $('#msg_'+loc).text('Update Status : '+data);
                            if(flag === 'se')
                                $('#msge_'+loc).text('Update Status : '+data);
                        }, "html");
            }
                
        </script>
        <script type="text/javascript">
            function popupWin(id, flag) {
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?viewEditDocument&idVisit=' + id + '&flag=' + flag;
                var left = (screen.width/2)-(1000/2);
                var top = (screen.height/2)-(1000/2);                
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';                
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }                
                return false;
            }
            
            function popupWinSub(id, flag) {
                var url = '${pageContext.request.contextPath}/shipVisit3Flow?viewEditDocumentSub&idVisitExtend=' + id + '&flag=' + flag;
                var left = (screen.width/2)-(1000/2);
                var top = (screen.height/2)-(1000/2);                
                var params = 'width=1000';
                params += ', height=1000';
                params += ', top=' + top;
                params += ', left=' + left;
                //params += ', fullscreen=yes';
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';                
                newwin = window.open(url, 'PopUp', params);
                if (window.focus) {
                    newwin.focus();
                }                
                return false;
            }
        </script>
        <style>
            .validateTips { border: 1px solid transparent; padding: 0.3em; font-weight: bold; font-size: 10pt;}
            em {color: red}
            br {margin: -3em}
            .tableHeader { vertical-align: top; text-align: right; font-weight: bold; }
            .tableValue { vertical-align: top; text-align: left; }
            .alertMsg { font-size: small; color: red }
        </style>
    </head>
    <body>
        <s:form beanclass="exatrez.stripes.action.ShipVisit3FlowAction" name="formList">
            <s:hidden name="counterId" />
            <s:hidden name="currentYear" />
            <s:hidden name="shipVisit3Id" />
            <s:hidden name="editFlag" />
            <s:hidden name="fromStage" />
            <div>
                <fieldset>                    
                    <div id="page-title">
                        <span class="title">Ship Visit</span>
                    </div>
                    <c:if test="${actionBean.fromStage eq 'kiv'}">
                        <s:submit name="visitKiv" value="Back" class="btn" />&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${actionBean.fromStage eq 'approve'}">
                        <s:submit name="visitApprove" value="Back" class="btn" />&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${!empty(actionBean.listCounter)}">
                        <div style="align: center">
                            <span class="sub-title">Ship visit target as per year ${actionBean.currentYear}</span>
                            <display:table class="tablecloth" name="${actionBean.listCounter}" requestURI="/shipVisit3Flow" id="line" style="width:50%">
                                <display:column title="Target Visit" property="target"/>
                                <display:column title="No. of visit" property="visited"/>
                                <display:column title="Total Balance"><c:out value="${line.target - line.visited}" /></display:column>                 
                            </display:table>
                        </div>
                    </c:if>                    
                    <c:if test="${actionBean.editFlag eq '1'}">
                        <div id="page-title">
                            <span class="title">Ship Visit - View / Edit Form</span>
                        </div>
                    </c:if>
                    <c:if test="${actionBean.editFlag eq '0'}">
                        <div id="page-title">
                            <span class="title">Ship Visit - View Form</span>
                        </div>
                    </c:if>
                    <s:messages/>
                    <s:errors/>
                    <c:if test="${actionBean.editFlag eq '1'}">
                        <p class="validateTips"><em>Note: </em>1) All form fields are required except Attachment.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2) All changes will be save automatically except Attachment and Upload.</p>
                    </c:if>
                    <table border="0" align="center" width="70%">
                        <tr>
                            <td width="15%" class="tableHeader">Vessel Name :</td>
                            <td width="55%" class="tableValue">
                                <%--<s:select name="shipVisit3.vessel.vesselId" id="vesselId" style="width:200px">
                                    <s:option value="">Please Choose</s:option>
                                    <s:options-collection collection="${list.vesselList}" label="vesselName" value="vesselId"/>
                                </s:select>--%>
                                ${actionBean.shipVisit3.vessel.vesselName}&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td class="tableHeader">Date Visit :</td>
                            <td class="tableValue">
                                <%--<s:text name="shipVisit3.dateVisit" id="datepicker2" formatType="date" formatPattern="dd/MM/yyyy" readonly="true"/>--%>     
                                <fmt:formatDate value="${actionBean.shipVisit3.dateVisit}" pattern="dd/MM/yyyy"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="tableHeader">Location / Port :</td>
                            <td class="tableValue">
                                <%--<s:text name="shipVisit3.location" id="location" size="55" class="uppercase"/>--%>
                                ${actionBean.shipVisit3.location}&nbsp;
                            </td>
                        </tr>
                        <c:set var="c" value="0" />
                        <c:forEach items="${actionBean.shipVisit3.listShipVisitSub}" var="object">
                            <c:set var="c" value="${c+1}" />
                            <tr>
                                <td class="tableHeader">${object.refShipVisitHeader.description} :</td>
                                <td class="tableValue">
                                    <c:if test="${empty(object.listSV3SubExtend)}">
                                        <c:if test="${actionBean.editFlag eq '0'}">
                                            ${object.details}&nbsp;
                                        </c:if>
                                        <c:if test="${actionBean.editFlag eq '1'}">
                                            <c:choose>
                                                <c:when test="${object.inputType eq 'M'}">
                                                    <s:textarea name="details" id="details_${c}" rows="4" cols="90" onchange="updateDetails('${object.shipVisit3SubId}',this.value,'s','${object.inputType}','${c}');">${object.details}</s:textarea><div class="alertMsg" id="msg_${c}"></div>
                                                </c:when>
                                                <c:otherwise>
                                                    <s:text name="details" id="details_${c}" size="55" class="uppercase" value="${object.details}" onchange="updateDetails('${object.shipVisit3SubId}',this.value,'s','${object.inputType}','${c}');"/><div class="alertMsg" id="msg_${c}"></div>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:if>
                                    </c:if>
                                    <c:if test="${!empty(object.listSV3SubExtend)}">
                                        <s:hidden name="details" id="details_${c}"/>
                                        <fieldset>
                                            <div>
                                                <c:set var="d" value="0" />
                                                <display:table class="tablecloth" name="${object.listSV3SubExtend}" requestURI="/shipVisit3Flow?viewEditForm" id="line2" >
                                                    <c:set var="d" value="${d+1}" />
                                                    <display:column title="Details" property="shipVisitSub.description" style="font-weight:bold;" />
                                                    <display:column title="Action">
                                                        <c:if test="${actionBean.editFlag eq '0'}">
                                                            <s:button name="" value="View..." class="btn" onclick="return popupWinSub('${line2.shipVisit3SubExtId}','${actionBean.editFlag}');"/>
                                                        </c:if>
                                                        <c:if test="${actionBean.editFlag eq '1'}">
                                                            <s:button name="" value="Upload..." class="btn" onclick="return popupWinSub('${line2.shipVisit3SubExtId}','${actionBean.editFlag}');"/>
                                                        </c:if>
                                                    </display:column>
                                                    <display:column title="Comments">
                                                        <%--<s:text name="details" id="sdetails_${d}" size="55" class="uppercase" value="${line2.details}"/>--%>
                                                        <c:if test="${actionBean.editFlag eq '0'}">
                                                            ${line2.details}&nbsp;
                                                        </c:if>
                                                        <c:if test="${actionBean.editFlag eq '1'}">
                                                            <c:choose>
                                                                <c:when test="${line2.inputType eq 'M'}">
                                                                    <s:textarea name="details" id="sdetails_${d}" rows="4" cols="60" onchange="updateDetails('${line2.shipVisit3SubExtId}',this.value,'se','${line2.inputType}','${d}');">${line2.details}</s:textarea><div class="alertMsg" id="msge_${d}"></div>
                                                                </c:when>
                                                                <c:otherwise>
                                                                    <s:text name="details" id="sdetails_${d}" size="55" class="uppercase" value="${line2.details}" onchange="updateDetails('${line2.shipVisit3SubExtId}',this.value,'se','${line2.inputType}','${d}');"/><div class="alertMsg" id="msge_${d}"></div>
                                                                </c:otherwise>
                                                            </c:choose>
                                                        </c:if>
                                                    </display:column>
                                                </display:table>
                                            </div>
                                        </fieldset>
                                    </c:if>
                                </td>
                            </tr>
                        </c:forEach>
                        <tr>
                            <td class="tableHeader">Attachment/s :</td>
                            <td class="tableValue">
                                <c:if test="${actionBean.editFlag eq '0'}">
                                    <s:button name="" value="View..." class="btn" onclick="return popupWin('${actionBean.shipVisit3Id}','${actionBean.editFlag}');"/>
                                </c:if>
                                <c:if test="${actionBean.editFlag eq '1'}">
                                    <s:button name="" value="Upload..." class="btn" onclick="return popupWin('${actionBean.shipVisit3Id}','${actionBean.editFlag}');"/>                            
                                </c:if>
                            </td>
                        </tr>
                    </table>
                    <br />
                        <c:if test="${actionBean.fromStage eq 'kiv'}">
                            <s:submit name="visitKiv" value="Back" class="btn" />&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${actionBean.fromStage eq 'approve'}">
                            <s:submit name="visitApprove" value="Back" class="btn" />&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${actionBean.fromStage eq 'reject'}">
                            <p>
                                <label>&nbsp;</label>
                                <s:submit name="visitReject" value="Back" class="btn" />&nbsp;&nbsp;
                                <s:submit name="" value="Re-Submit" class="btn" onclick="reSubmit('${actionBean.shipVisit3Id}','1','resubmit');"/>
                            </p>
                        </c:if>
                        <c:if test="${actionBean.fromStage eq 'resubmit'}">
                            <p>
                                <label>&nbsp;</label>
                                <s:submit name="visitReject" value="Back" class="btn" />&nbsp;&nbsp;
                                <s:submit name="reSubmit" value="Submit" class="btn" onclick="autoComplete();"/>
                            </p>
                        </c:if>
                    
                </fieldset>
            </div>
            <c:if test="${actionBean.editFlag eq '0' or actionBean.fromStage eq 'resubmit'}">
                <div>
                    <fieldset>
                        <div id="page-title">
                            <span class="title">History report</span>
                        </div>
                        <display:table class="tablecloth" name="${actionBean.shipVisit3.listHistory}" requestURI="/shipVisit3Flow" id="line" style="width:50%">
                            <display:column title="No." ><center>${line_rowNum}.</center></display:column>
                            <display:column title="Status">
                                <c:if test="${line.status eq 'R'}">
                                    Rejected
                                </c:if>
                                <c:if test="${line.status eq 'A'}">
                                    Approved
                                </c:if>
                            </display:column>
                            <display:column title="Remarks" property="rejectNote" />
                            <display:column title="Date Approval" sortable="true"><fmt:formatDate value="${line.infoAudit.createDate}" pattern="dd/MM/yyyy hh:mm:ss a"/></display:column>
                            <display:column title="Approval By" sortable="true" property="verifierId.userId"/>
                        </display:table>                    
                    </fieldset>
                </div>
            </c:if>
        </s:form>
    </body>
</html>
